﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using IPC.Communication.Core.Address;

namespace IPC.Communication.Profinet.Melsec.Helper
{
    public class McHelper
    {
        private static int GetReadWordLength(McType type)
        {
            if (type == McType.McBinary || type == McType.McRBinary)
            {
                return 950;
            }
            return 460;
        }

        private static int GetReadBoolLength(McType type)
        {
            if (type == McType.McBinary || type == McType.McRBinary)
            {
                return 7168;
            }
            return 3584;
        }

        public static OperateResult<byte[]> Read(IReadWriteMc mc, string address, ushort length)
        {
            if ((mc.McType == McType.McBinary && address.StartsWith("s=")) || address.StartsWith("S="))
            {
                return McBinaryHelper.ReadTags(mc, new string[1]
			{
				address.Substring(2)
			}, new ushort[1]
			{
				length
			});
            }
            if ((mc.McType == McType.McBinary || mc.McType == McType.MCAscii) && Regex.IsMatch(address, "ext=[0-9]+;", RegexOptions.IgnoreCase))
            {
                string value = Regex.Match(address, "ext=[0-9]+;").Value;
                ushort extend = ushort.Parse(Regex.Match(value, "[0-9]+").Value);
                return ReadExtend(mc, extend, address.Substring(value.Length), length);
            }
            if ((mc.McType == McType.McBinary || mc.McType == McType.MCAscii) && Regex.IsMatch(address, "mem=", RegexOptions.IgnoreCase))
            {
                return ReadMemory(mc, address.Substring(4), length);
            }
            if ((mc.McType == McType.McBinary || mc.McType == McType.MCAscii) && Regex.IsMatch(address, "module=[0-9]+;", RegexOptions.IgnoreCase))
            {
                string value2 = Regex.Match(address, "module=[0-9]+;").Value;
                ushort module = ushort.Parse(Regex.Match(value2, "[0-9]+").Value);
                return ReadSmartModule(mc, module, address.Substring(value2.Length), (ushort)(length * 2));
            }
            OperateResult<McAddressData> operateResult = mc.McAnalysisAddress(address, length);
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult);
            }
            List<byte> list = new List<byte>();
            ushort num = 0;
            while (num < length)
            {
                ushort num2 = (ushort)Math.Min(length - num, GetReadWordLength(mc.McType));
                operateResult.Content.Length = num2;
                byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadMcCoreCommand(operateResult.Content, isBit: false) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadMcCoreCommand(operateResult.Content, isBit: false) : ((mc.McType == McType.McRBinary) ? MelsecMcRNet.BuildReadMcCoreCommand(operateResult.Content, isBit: false) : null));
                OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
                if (!operateResult2.IsSuccess)
                {
                    return operateResult2;
                }
                list.AddRange(mc.ExtractActualData(operateResult2.Content, isBit: false));
                num = (ushort)(num + num2);
                if (operateResult.Content.McDataType.DataType == 0)
                {
                    operateResult.Content.AddressStart += num2;
                }
                else
                {
                    operateResult.Content.AddressStart += num2 * 16;
                }
            }
            return OperateResult.CreateSuccessResult(list.ToArray());
        }

        public static OperateResult Write(IReadWriteMc mc, string address, byte[] value)
        {
            OperateResult<McAddressData> operateResult = mc.McAnalysisAddress(address, 0);
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult);
            }
            byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildWriteWordCoreCommand(operateResult.Content, value) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiWriteWordCoreCommand(operateResult.Content, value) : ((mc.McType == McType.McRBinary) ? MelsecMcRNet.BuildWriteWordCoreCommand(operateResult.Content, value) : null));
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
            if (!operateResult2.IsSuccess)
            {
                return operateResult2;
            }
            return OperateResult.CreateSuccessResult();
        }

        public static OperateResult<bool[]> ReadBool(IReadWriteMc mc, string address, ushort length)
        {
            if (address.IndexOf('.') > 0)
            {
                string[] array = address.SplitDot();
                int num = 0;
                try
                {
                    num = Convert.ToInt32(array[1]);
                }
                catch (Exception ex)
                {
                    return new OperateResult<bool[]>("Bit Index format wrong, " + ex.Message);
                }
                ushort length2 = (ushort)((length + num + 15) / 16);
                OperateResult<byte[]> operateResult = mc.Read(array[0], length2);
                if (!operateResult.IsSuccess)
                {
                    return OperateResult.CreateFailedResult<bool[]>(operateResult);
                }
                return OperateResult.CreateSuccessResult(operateResult.Content.ToBoolArray().SelectMiddle(num, length));
            }
            OperateResult<McAddressData> operateResult2 = mc.McAnalysisAddress(address, length);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<bool[]>(operateResult2);
            }
            List<bool> list = new List<bool>();
            ushort num2 = 0;
            while (num2 < length)
            {
                ushort num3 = (ushort)Math.Min(length - num2, GetReadBoolLength(mc.McType));
                operateResult2.Content.Length = num3;
                byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadMcCoreCommand(operateResult2.Content, isBit: true) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadMcCoreCommand(operateResult2.Content, isBit: true) : ((mc.McType == McType.McRBinary) ? MelsecMcRNet.BuildReadMcCoreCommand(operateResult2.Content, isBit: true) : null));
                OperateResult<byte[]> operateResult3 = mc.ReadFromCoreServer(send);
                if (!operateResult3.IsSuccess)
                {
                    return OperateResult.CreateFailedResult<bool[]>(operateResult3);
                }
                list.AddRange((from m in mc.ExtractActualData(operateResult3.Content, isBit: true)
                               select m == 1).Take(num3).ToArray());
                num2 = (ushort)(num2 + num3);
                operateResult2.Content.AddressStart += num3;
            }
            return OperateResult.CreateSuccessResult(list.ToArray());
        }

        public static OperateResult Write(IReadWriteMc mc, string address, bool[] values)
        {
            OperateResult<McAddressData> operateResult = mc.McAnalysisAddress(address, 0);
            if (!operateResult.IsSuccess)
            {
                return operateResult;
            }
            byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildWriteBitCoreCommand(operateResult.Content, values) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiWriteBitCoreCommand(operateResult.Content, values) : ((mc.McType == McType.McRBinary) ? MelsecMcRNet.BuildWriteBitCoreCommand(operateResult.Content, values) : null));
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
            if (!operateResult2.IsSuccess)
            {
                return operateResult2;
            }
            return OperateResult.CreateSuccessResult();
        }

        //[AsyncStateMachine(typeof(<ReadAsync>d__6))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadAsync(IReadWriteMc mc, string address, ushort length)
        //{
        //    <ReadAsync>d__6 stateMachine = new <ReadAsync>d__6();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<WriteAsync>d__7))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> WriteAsync(IReadWriteMc mc, string address, byte[] value)
        //{
        //    <WriteAsync>d__7 stateMachine = new <WriteAsync>d__7();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.value = value;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ReadBoolAsync>d__8))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<bool[]>> ReadBoolAsync(IReadWriteMc mc, string address, ushort length)
        //{
        //    <ReadBoolAsync>d__8 stateMachine = new <ReadBoolAsync>d__8();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<WriteAsync>d__9))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> WriteAsync(IReadWriteMc mc, string address, bool[] values)
        //{
        //    <WriteAsync>d__9 stateMachine = new <WriteAsync>d__9();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.values = values;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        public static OperateResult<byte[]> ReadRandom(IReadWriteMc mc, string[] address)
        {
            McAddressData[] array = new McAddressData[address.Length];
            for (int i = 0; i < address.Length; i++)
            {
                OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address[i], 1);
                if (!operateResult.IsSuccess)
                {
                    return OperateResult.CreateFailedResult<byte[]>(operateResult);
                }
                array[i] = operateResult.Content;
            }
            byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadRandomWordCommand(array) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadRandomWordCommand(array) : null);
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult2);
            }
            return OperateResult.CreateSuccessResult(mc.ExtractActualData(operateResult2.Content, isBit: false));
        }

        public static OperateResult<byte[]> ReadRandom(IReadWriteMc mc, string[] address, ushort[] length)
        {
            if (length.Length != address.Length)
            {
                return new OperateResult<byte[]>(StringResources.Language.TwoParametersLengthIsNotSame);
            }
            McAddressData[] array = new McAddressData[address.Length];
            for (int i = 0; i < address.Length; i++)
            {
                OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address[i], length[i]);
                if (!operateResult.IsSuccess)
                {
                    return OperateResult.CreateFailedResult<byte[]>(operateResult);
                }
                array[i] = operateResult.Content;
            }
            byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadRandomCommand(array) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadRandomCommand(array) : null);
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult2);
            }
            return OperateResult.CreateSuccessResult(mc.ExtractActualData(operateResult2.Content, isBit: false));
        }

        public static OperateResult<short[]> ReadRandomInt16(IReadWriteMc mc, string[] address)
        {
            OperateResult<byte[]> operateResult = ReadRandom(mc, address);
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<short[]>(operateResult);
            }
            return OperateResult.CreateSuccessResult(mc.ByteTransform.TransInt16(operateResult.Content, 0, address.Length));
        }

        public static OperateResult<ushort[]> ReadRandomUInt16(IReadWriteMc mc, string[] address)
        {
            OperateResult<byte[]> operateResult = ReadRandom(mc, address);
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<ushort[]>(operateResult);
            }
            return OperateResult.CreateSuccessResult(mc.ByteTransform.TransUInt16(operateResult.Content, 0, address.Length));
        }

        //[AsyncStateMachine(typeof(<ReadRandomAsync>d__14))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadRandomAsync(IReadWriteMc mc, string[] address)
        //{
        //    <ReadRandomAsync>d__14 stateMachine = new <ReadRandomAsync>d__14();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ReadRandomAsync>d__15))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadRandomAsync(IReadWriteMc mc, string[] address, ushort[] length)
        //{
        //    <ReadRandomAsync>d__15 stateMachine = new <ReadRandomAsync>d__15();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ReadRandomInt16Async>d__16))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<short[]>> ReadRandomInt16Async(IReadWriteMc mc, string[] address)
        //{
        //    <ReadRandomInt16Async>d__16 stateMachine = new <ReadRandomInt16Async>d__16();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<short[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ReadRandomUInt16Async>d__17))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<ushort[]>> ReadRandomUInt16Async(IReadWriteMc mc, string[] address)
        //{
        //    <ReadRandomUInt16Async>d__17 stateMachine = new <ReadRandomUInt16Async>d__17();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<ushort[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        public static OperateResult<byte[]> ReadMemory(IReadWriteMc mc, string address, ushort length)
        {
            OperateResult<byte[]> operateResult = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadMemoryCommand(address, length) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadMemoryCommand(address, length) : null);
            if (!operateResult.IsSuccess)
            {
                return operateResult;
            }
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(operateResult.Content);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult2);
            }
            return OperateResult.CreateSuccessResult(mc.ExtractActualData(operateResult2.Content, isBit: false));
        }

        //[AsyncStateMachine(typeof(<ReadMemoryAsync>d__19))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadMemoryAsync(IReadWriteMc mc, string address, ushort length)
        //{
        //    <ReadMemoryAsync>d__19 stateMachine = new <ReadMemoryAsync>d__19();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        public static OperateResult<byte[]> ReadSmartModule(IReadWriteMc mc, ushort module, string address, ushort length)
        {
            OperateResult<byte[]> operateResult = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadSmartModule(module, address, length) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadSmartModule(module, address, length) : null);
            if (!operateResult.IsSuccess)
            {
                return operateResult;
            }
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(operateResult.Content);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult2);
            }
            return OperateResult.CreateSuccessResult(mc.ExtractActualData(operateResult2.Content, isBit: false));
        }

        //[AsyncStateMachine(typeof(<ReadSmartModuleAsync>d__21))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadSmartModuleAsync(IReadWriteMc mc, ushort module, string address, ushort length)
        //{
        //    <ReadSmartModuleAsync>d__21 stateMachine = new <ReadSmartModuleAsync>d__21();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.module = module;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        public static OperateResult<byte[]> ReadExtend(IReadWriteMc mc, ushort extend, string address, ushort length)
        {
            OperateResult<McAddressData> operateResult = mc.McAnalysisAddress(address, length);
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult);
            }
            byte[] send = (mc.McType == McType.McBinary) ? McBinaryHelper.BuildReadMcCoreExtendCommand(operateResult.Content, extend, isBit: false) : ((mc.McType == McType.MCAscii) ? McAsciiHelper.BuildAsciiReadMcCoreExtendCommand(operateResult.Content, extend, isBit: false) : null);
            OperateResult<byte[]> operateResult2 = mc.ReadFromCoreServer(send);
            if (!operateResult2.IsSuccess)
            {
                return OperateResult.CreateFailedResult<byte[]>(operateResult2);
            }
            return OperateResult.CreateSuccessResult(mc.ExtractActualData(operateResult2.Content, isBit: false));
        }

        //[AsyncStateMachine(typeof(<ReadExtendAsync>d__23))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<byte[]>> ReadExtendAsync(IReadWriteMc mc, ushort extend, string address, ushort length)
        //{
        //    <ReadExtendAsync>d__23 stateMachine = new <ReadExtendAsync>d__23();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.extend = extend;
        //    stateMachine.address = address;
        //    stateMachine.length = length;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        public static OperateResult RemoteRun(IReadWriteMc mc)
        {
            return (mc.McType == McType.McBinary) ? mc.ReadFromCoreServer(new byte[8]
		{
			1,
			16,
			0,
			0,
			1,
			0,
			0,
			0
		}) : ((mc.McType == McType.MCAscii) ? mc.ReadFromCoreServer(Encoding.ASCII.GetBytes("1001000000010000")) : new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction));
        }

        public static OperateResult RemoteStop(IReadWriteMc mc)
        {
            return (mc.McType == McType.McBinary) ? mc.ReadFromCoreServer(new byte[6]
		{
			2,
			16,
			0,
			0,
			1,
			0
		}) : ((mc.McType == McType.MCAscii) ? mc.ReadFromCoreServer(Encoding.ASCII.GetBytes("100200000001")) : new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction));
        }

        public static OperateResult RemoteReset(IReadWriteMc mc)
        {
            return (mc.McType == McType.McBinary) ? mc.ReadFromCoreServer(new byte[6]
		{
			6,
			16,
			0,
			0,
			1,
			0
		}) : ((mc.McType == McType.MCAscii) ? mc.ReadFromCoreServer(Encoding.ASCII.GetBytes("100600000001")) : new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction));
        }

        public static OperateResult<string> ReadPlcType(IReadWriteMc mc)
        {
            OperateResult<byte[]> operateResult = (mc.McType == McType.McBinary) ? mc.ReadFromCoreServer(new byte[4]
		{
			1,
			1,
			0,
			0
		}) : ((mc.McType == McType.MCAscii) ? mc.ReadFromCoreServer(Encoding.ASCII.GetBytes("01010000")) : new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction));
            if (!operateResult.IsSuccess)
            {
                return OperateResult.CreateFailedResult<string>(operateResult);
            }
            return OperateResult.CreateSuccessResult(Encoding.ASCII.GetString(operateResult.Content, 0, 16).TrimEnd());
        }

        public static OperateResult ErrorStateReset(IReadWriteMc mc)
        {
            return (mc.McType == McType.McBinary) ? mc.ReadFromCoreServer(new byte[4]
		{
			23,
			22,
			0,
			0
		}) : ((mc.McType == McType.MCAscii) ? mc.ReadFromCoreServer(Encoding.ASCII.GetBytes("16170000")) : new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction));
        }

        //[AsyncStateMachine(typeof(<RemoteRunAsync>d__29))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> RemoteRunAsync(IReadWriteMc mc)
        //{
        //    <RemoteRunAsync>d__29 stateMachine = new <RemoteRunAsync>d__29();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<RemoteStopAsync>d__30))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> RemoteStopAsync(IReadWriteMc mc)
        //{
        //    <RemoteStopAsync>d__30 stateMachine = new <RemoteStopAsync>d__30();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<RemoteResetAsync>d__31))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> RemoteResetAsync(IReadWriteMc mc)
        //{
        //    <RemoteResetAsync>d__31 stateMachine = new <RemoteResetAsync>d__31();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ReadPlcTypeAsync>d__32))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult<string>> ReadPlcTypeAsync(IReadWriteMc mc)
        //{
        //    <ReadPlcTypeAsync>d__32 stateMachine = new <ReadPlcTypeAsync>d__32();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}

        //[AsyncStateMachine(typeof(<ErrorStateResetAsync>d__33))]
        //[DebuggerStepThrough]
        //public static Task<OperateResult> ErrorStateResetAsync(IReadWriteMc mc)
        //{
        //    <ErrorStateResetAsync>d__33 stateMachine = new <ErrorStateResetAsync>d__33();
        //    stateMachine.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
        //    stateMachine.mc = mc;
        //    stateMachine.<>1__state = -1;
        //    stateMachine.<>t__builder.Start(ref stateMachine);
        //    return stateMachine.<>t__builder.Task;
        //}
    }
}
